﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Microsoft.Office.PowerPoint.STAMP.Core
{
    /// <summary>
    /// Class that holds the style of each caption.
    /// </summary>
    public class CaptionStyle : ICloneable
    {
        private const string DefaultFontFamilyName = "Calibri";
        
        private const double DefaultOpacity = 0.2;
        private const int DefaultCaptionLines = 3;
        
        private static readonly FontFamily DefaultFontFamily = new FontFamily(DefaultFontFamilyName);
        private const CaptionLocation DefaultCaptionLocation = CaptionLocation.SlideBottom;
        private const FontStyle DefaultFontStyle = System.Drawing.FontStyle.Regular;
        private const FontStyle DefaultFontWeight = System.Drawing.FontStyle.Regular;
        private const TextDecorationAttributeValue DefaultTextDecorationAttributeValue = TextDecorationAttributeValue.none;
        private const TextAlignAttibuteValue DefaultTextAlignAttibuteValue = TextAlignAttibuteValue.start;
        private static readonly Color DefaultFontColor = Color.White;
        private static readonly Color DefaultBackgroundColor = Color.Black;
        private Length DefaultFontSize = new Length { Unit = LengthUnit.Pixel,Value = 30};

        /// <summary>
        /// Default constructor for caption style class.
        /// </summary>
        public CaptionStyle()
        {
            FontFamily = DefaultFontFamily;
          //  FontSize = DefaultFontSize;
            Opacity = DefaultOpacity;
            CaptionLines = DefaultCaptionLines;
            CaptionLocation = DefaultCaptionLocation;

            // styles in the txt file
            FontStyle = DefaultFontStyle;
            FontWeight = DefaultFontWeight;
            TextDecorationStyleProperty = DefaultTextDecorationAttributeValue;
            TextAlignStyleProperty = DefaultTextAlignAttibuteValue;
            BackgroundColor = DefaultBackgroundColor;
            FontColor = DefaultFontColor;

            Id = Guid.NewGuid().ToString();
        }

        public bool CaptionDisplayArea { get; set; }

        public FontFamily FontFamily { get; set; }
        public string Id { get; set; }
        /// <summary>
        /// Gets or sets the font style.
        /// </summary>
        public FontStyle FontStyle { get; set; }

        /// <summary>
        /// Gets or sets the font weight.
        /// </summary>
        public FontStyle FontWeight { get; set; }

        /// <summary>
        /// Gets or sets the text docoration attribute.
        /// </summary>
        public TextDecorationAttributeValue TextDecorationStyleProperty { get; set; }

        /// <summary>
        /// Gets or sets the text align attribute.
        /// </summary>
        public TextAlignAttibuteValue TextAlignStyleProperty { get; set; }
       

        /// <summary>
        /// Gets or sets the background color.
        /// </summary>
        public Color BackgroundColor { get; set; }

        /// <summary>
        /// Gets or sets the font color.
        /// </summary>
        public Color FontColor { get; set; }

        /// <summary>
        /// Gets or sets the caption location.
        /// </summary>
        public CaptionLocation CaptionLocation { get; set; }

        /// <summary>
        /// Gets or sets the the caption lines.
        /// </summary>
        public int CaptionLines { get; set; }

        /// <summary>
        /// Gets or sets the text size for the caption.
        /// </summary>
        public Length FontSize { get; set; }

        /// <summary>
        /// Font family used in the captions style.
        /// </summary>
        public string FontFamilyName { get; set; }

        /// <summary>
        /// Gets or sets the percent that the caption is transparent (as a value between 0 and 1.0).
        /// </summary>
        public double Opacity { get; set; }

        object ICloneable.Clone()
        {
            return Clone();
        }
        public CaptionStyle Clone()
        {
            return (CaptionStyle)MemberwiseClone();
        }
    }

    /// <summary>
    /// Enumeration of text decoration attributes.
    /// </summary>
    public enum TextDecorationAttributeValue
    {
        /// <summary>
        /// Text decoration of 'none'
        /// </summary>
        none,
        /// <summary>
        /// Text decoration of 'underline'
        /// </summary>
        underline,
        /// <summary>
        /// Text decoration of 'lineThrough'
        /// </summary>
        lineThrough,
        /// <summary>
        /// Text decoration of 'overline'
        /// </summary>
        overline,
    };

    /// <summary>
    /// Enumeration of text align attributes.
    /// </summary>
    public enum TextAlignAttibuteValue
    {
        /// <summary>
        /// Text align of 'left'
        /// </summary>
        left,
        /// <summary>
        /// Text align of 'center'
        /// </summary>
        center,
        /// <summary>
        /// Text align of 'right'
        /// </summary>
        right,
        /// <summary>
        /// Text align of 'start'
        /// </summary>
        start,
        /// <summary>
        /// Text align of 'end'
        /// </summary>
        end,
    };

    /// <summary>
    /// Enumeration of font style attributes.
    /// </summary>
    public enum FontStyleAttributeValue
    {
        /// <summary>
        /// Font style of 'normal'
        /// </summary>
        normal,
        /// <summary>
        /// Font style of 'italic'
        /// </summary>
        italic,
        /// <summary>
        /// Font style of 'oblique'
        /// </summary>
        oblique,
    };

    /// <summary>
    /// Enumeration of font weight attributes.
    /// </summary>
    public enum FontWeightAttributeValue
    {
        /// <summary>
        /// Font weight of 'normal'
        /// </summary>
        normal,
        /// <summary>
        /// Font weight of 'bold'
        /// </summary>
        bold,
    };

    /// <summary>
    /// Represents a unit of length to be applied to a caption property.
    /// </summary>
    public enum LengthUnit
    {
        Pixel = 0,
        Em,
        Cell,
        Percent
    }

    /// <summary>
    /// Represents a length to be applied to a caption property..
    /// </summary>
    public class Length
    {
        /// <summary>
        /// The numeric value of this length.
        /// </summary>
        public double Value { get; set; }

        /// <summary>
        /// The unit of this length.
        /// </summary>
        public LengthUnit Unit { get; set; }

        public double ToPixelLength(double containerLength = 0)
        {
            return Unit == LengthUnit.Percent
                    ? Value * containerLength
                    : Value;
        }
    }
}